<template>
    <div class="firmtotal">
        <div class="seachDiv">
            <el-form :model="firmSearch" inline ref="firmSearchForm" style="align-items: center;">
                <el-form-item style="margin-bottom: 0px;" label="时间" prop="activity_date">
                    <el-date-picker value-format="yyyy-MM-dd" v-model="firmSearch.activity_date" type="date" placeholder="选择日期">
                    </el-date-picker>
                </el-form-item>
                <el-form-item style="margin-bottom: 0px;" label="主题" prop="activity_theme">
                    <el-input type="text" v-model="firmSearch.activity_theme" placeholder="请输入主题名称"></el-input>
                </el-form-item>
                <el-button type="primary" plain @click="restForm">重置</el-button>
                <el-button type="primary" @click="getList">查询</el-button>
            </el-form>
        </div>
        <div class="tableDiv">
            <el-button type="primary" @click="addFirm">新增</el-button>
            <el-table :data="tableData" :height="tabelHeight" class="tableInDiv">
                <el-table-column label="序号" width="50" align="center" type="index">
                </el-table-column>
                <el-table-column label="日期" align="center" prop="activity_date">
                </el-table-column>
                <el-table-column label="主题" align="center" prop="activity_theme">
                    <template slot-scope="scope">
                        <div style="color: #409eff; cursor: pointer" @click="editUser(scope.row.id, '活动详情')">
                            {{ scope.row.activity_theme }}
                        </div>
                    </template>
                </el-table-column>
                <el-table-column label="活动地点" align="center" prop="activity_addr">
                </el-table-column>
                <el-table-column label="活动内容" align="center" prop="activity_content" show-overflow-tooltip>
                </el-table-column>
                <el-table-column label="参训人员" align="center" prop="participate_count">
                </el-table-column>
                <el-table-column label="请假人员" align="center" prop="leave_count">
                </el-table-column>
                <el-table-column label="操作" align="center">
                    <template slot-scope="scope">
                        <el-button type="text" @click="editUser(scope.row.id, '编辑活动')">编辑</el-button>
                        <el-button type="text" style="color: #F56C6C;" @click="delUser(scope.row.id)">删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-pagination class="page" @current-change="handleCurrentChange" :current-page.sync="currentPage"
                :page-size="10" layout="total, prev, pager, next" :total="pageTotal">
            </el-pagination>
        </div>
        <addActive ref="firmDialog"></addActive>
    </div>
</template>

<script>
import addActive from './addActive.vue'
export default {
    components: {
        addActive
    },
    data() {
        return {
            pageTotal: null,
            currentPage: 1,
            firmSearch: {
                activity_date: '',
                activity_theme: ''
            },
            tableData: [],
            tabelHeight: 'calc(100% - 40px)'
        }
    },
    methods: {
        gotoHall(val) {
            this.$router.push({
                path: 'ceremonyHallMangent',
                query: { id: val }
            })
        },
        delUser(id) {
            this.$confirm('此操作将删除该信息, 是否继续删除?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                confirmButtonClass: 'btnConfirm',
                cancelButtonClass: 'btnCancel',
                type: 'warning'
            }).then(() => {
                this.$api.delActive(id).then(res => {
                    this.$message.success(res.message)
                    this.getList()
                }).catch(err => {
                    this.$message.error(err.message)
                })
            }).catch(() => {
                this.$message({
                    type: 'info',
                    message: '已取消操作'
                })
            })
        },
        getList() {
            let search = {
                ...this.firmSearch,
                page: this.currentPage,
                size: 10
            }
            this.$api.getActiveList(search).then(res => {
                this.tableData = res.data
                this.pageTotal = res.total
            }).catch(err => {
                this.$message.error(err.message)
            })
        },
        handleCurrentChange(val) {
            this.currentPage = val;
            this.getList()
        },
        restForm() {
            this.$refs.firmSearchForm.resetFields()
            this.currentPage = 1
            this.getList()
        },
        addFirm() {
            this.$refs.firmDialog.addNewFirm()
        },
        editUser(id, val) {
            this.$refs.firmDialog.getDetail(id, val)
        }
    },
    mounted() {
        this.getList()
    }
}
</script>

<style lang="less" scoped>
.firmtotal {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    box-sizing: border-box;

    .seachDiv {
        width: calc(100% - 40px);
        height: 100px;
        background-color: #fff;
        border-radius: 20px;
        padding: 20px;
        display: flex;
        align-items: center;
    }

    .tableDiv {
        margin-top: 20px;
        width: calc(100% - 40px);
        height: calc(100% - 180px);
        background-color: #fff;
        border-radius: 20px;
        padding: 20px 20px 0px 20px;
        display: flex;
        flex-direction: column;
        align-items: flex-end;

        .tableInDiv {
            width: 100%;
            height: calc(100% - 20px);
            overflow-y: auto;
            margin-top: 10px;
            box-sizing: border-box;
            overflow: hidden;
        }
    }
}
</style>